package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
    todo:开启MinioProperties支持  将MinioClient加入到ioc容器
 */
@EnableConfigurationProperties(MinioProperties.class)
@Configuration
@ConditionalOnProperty(prefix = "minio",value = "endpoint")
public class MinioConfiguration {
    //方法1：
//    @Autowired
//    private MinioProperties minioProperties;
    //方法2：
//    在方法的形参列表中直接将MinioProperties传入
    @Bean
    public MinioClient minioClient(MinioProperties minioProperties){
        MinioClient minioClient = MinioClient.builder().endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey()).build();
        return minioClient;
    }
}
